//
//  RwdOriginalView.swift
//  Weibo_rwd
//
//  Created by 任文迪 on 16/7/13.
//  Copyright © 2016年 spaceX. All rights reserved.
//

import UIKit
import SnapKit

class RwdBottomToolBar: UIView {
    
    var statusModel:RwdStatusViewModel? {
        didSet{
            
            retweetButton.setTitle(statusModel?.retweetStr, forState: .Normal)
            
            comentButton.setTitle(statusModel?.commentStr, forState: .Normal)
            
            unlikeButton.setTitle(statusModel?.unlikeStr, forState: .Normal)
        }
        
        
    }
    
    
    //懒加载的方式添加三个button
    private lazy var retweetButton: UIButton = self.createButton("timeline_icon_retweet", title: "转发")
    private lazy var comentButton: UIButton = self.createButton("timeline_icon_comment", title: "评论")
    private lazy var unlikeButton: UIButton = self.createButton("timeline_icon_unlike", title: "赞")
    //懒加载两条竖线
    private lazy var leftLine: UIView = {
        let leftView = UIView()
        leftView.backgroundColor = UIColor.grayColor()
        
        return leftView
        }()
    
    private lazy var rightLine: UIView = {
        let rightLine = UIView()
        rightLine.backgroundColor = UIColor.grayColor()
        return rightLine
    }()
    //重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        SetUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func SetUpUI() {
        //添加子控件
        addSubview(retweetButton)
        addSubview(comentButton)
        addSubview(unlikeButton)
        //设置约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(comentButton)
        }
        comentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(comentButton.snp_trailing)
            make.trailing.equalTo(self)
            make.bottom.equalTo(self)
            make.top.equalTo(self)
        }
        addSubview(leftLine)
        leftLine.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            make.top.equalTo(self).offset(8)
            make.bottom.equalTo(self).offset(-8)
            make.width.equalTo(1)
            
        }
        addSubview(rightLine)
        rightLine.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(comentButton.snp_trailing)
            make.top.equalTo(self).offset(8)
            make.bottom.equalTo(self).offset(-8)
            make.width.equalTo(1)
        }
        
    }
    
    
    
    //设置一个创建button的公共类的方法
    private func createButton(imageName:String,title:String)->UIButton {
        //创建
        let button = UIButton()
        //设置背景图片
        button.setImage(UIImage(named: imageName), forState: .Normal)
        //设置文字
        button.setTitle(title, forState: .Normal)
        //设置文字大小
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        //设置文字颜色
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        
        button.backgroundColor = UIColor(white: 0.9, alpha: 0.5)
        
//        button.backgroundColor = UIColor(patternImage: UIImage(named: "timeline_card_bottom_background")!)
        return button
        
    }
    
    
}
